﻿
USE DBSHOP


------------------------------------------------------------------------------------------
/*
	sp_ADD_CATEGORY : Thêm 1 chủng loại sản phẩm
*/
GO

if exists (select * from sysobjects where id = object_id('dbo.sp_ADD_CATEGORY') 
and sysstat & 0xf = 4)  drop procedure dbo.sp_ADD_CATEGORY

GO

CREATE PROCEDURE sp_ADD_CATEGORY
(	
	@NAME NVARCHAR(200),		
	@DESCRIPTION NVARCHAR(200),
	@ACTIVE_HOME BIT,
	@RECORD_STATUS BIT
)

AS

INSERT INTO CATEGORY 
VALUES(@NAME, @DESCRIPTION, @ACTIVE_HOME, @RECORD_STATUS)

------------------------------------------------------------------------------------------
/*
	sp_UPDATE_CATEGORY : Cập nhật 1 chủng loại sản phẩm
*/
GO
if exists (select * from sysobjects where id = object_id('dbo.sp_UPDATE_CATEGORY') 
and sysstat & 0xf = 4)  drop procedure dbo.sp_UPDATE_CATEGORY

GO

CREATE PROCEDURE sp_UPDATE_CATEGORY
(
	@ID INT,	
	@NAME NVARCHAR(200),		
	@DESCRIPTION NVARCHAR(400),	
	@ACTIVE_HOME BIT,
	@RECORD_STATUS BIT
)

AS

UPDATE CATEGORY
SET  NAME = @NAME
	,DESCRIPTION = @DESCRIPTION
	,ACTIVE_HOME = @ACTIVE_HOME
	,RECORD_STATUS = @RECORD_STATUS
WHERE ID = @ID


------------------------------------------------------------------------------------------
/*
	sp_ADD_PRODUCT : Thêm mới 1 sản phẩm
*/

GO

if exists (select * from sysobjects where id = object_id('dbo.sp_ADD_PRODUCT') 
and sysstat & 0xf = 4)  drop procedure dbo.sp_ADD_PRODUCT

GO

CREATE PROCEDURE sp_ADD_PRODUCT
(
	@CATID INT,
	@NAME NVARCHAR(300),
	@PRICE FLOAT,		
	@PROMOTION_PRICE FLOAT,
	@IMAGE NTEXT,
	@DESCRIPTIONS NTEXT,
	@SORTED INT,
	@RECORD_STATUS BIT
)

AS

INSERT INTO PRODUCT 
VALUES( @CATID, @NAME, @PRICE, @PROMOTION_PRICE, @IMAGE, @DESCRIPTIONS, @SORTED, @RECORD_STATUS)

------------------------------------------------------------------------------------------
/*
	sp_UPDATE_PRODUCT : Sửa 1 sản phẩm
*/

GO
if exists (select * from sysobjects where id = object_id('dbo.sp_UPDATE_PRODUCT') 
and sysstat & 0xf = 4)  drop procedure dbo.sp_UPDATE_PRODUCT

GO

CREATE PROCEDURE sp_UPDATE_PRODUCT
(
	@ID INT,
	@CATID INT,
	@NAME NVARCHAR(300),
	@PRICE FLOAT,		
	@PROMOTION_PRICE FLOAT,
	@IMAGE NTEXT,
	@DESCRIPTIONS NTEXT,
	@SORTED INT,
	@RECORD_STATUS BIT
)

AS

UPDATE PRODUCT
SET  CATID = @CATID
	,NAME = @NAME
	,PRICE = @PRICE
	,PROMOTION_PRICE = @PROMOTION_PRICE
	,IMAGE = @IMAGE
	,DESCRIPTIONS = @DESCRIPTIONS
	,SORTED = @SORTED
	,RECORD_STATUS = @RECORD_STATUS
WHERE ID = @ID


------------------------------------------------------------------------------------------
/*
	sp_UPDATE_ORDER : Cập nhật 1 đơn hàng
*/
GO

if exists (select * from sysobjects where id = object_id('sp_UPDATE_ORDER') 
and sysstat & 0xf = 4)  drop procedure sp_UPDATE_ORDER

GO

CREATE PROCEDURE sp_UPDATE_ORDER
(	@ID INT,	
	@TYPE_CHECKOUT TINYINT,	
	@RECORD_STATUS BIT
)

AS

UPDATE [ORDER] 
SET TYPE_CHECKOUT = @TYPE_CHECKOUT,
	RECORD_STATUS = @RECORD_STATUS
WHERE ID=@ID;